<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use ms\modules\article\models\ArticleNav;

/* @var $this yii\web\View */
/* @var $model ms\modules\article\models\ArticleInfo */
$this->title = '更新文章: ' . ' ' . $model->title;
$this->params['breadcrumbs'][] = ['label' => 'Article Infos', 'url' => ['index']];
$this->params['breadcrumbs'][] = ['label' => $model->title, 'url' => ['view', 'id' => $model->id]];
$this->params['breadcrumbs'][] = 'Update';
?>
<div class="article-info-update">

    <h1><?= Html::encode($this->title) ?></h1>
		<?php $form = ActiveForm::begin([
	      'options' => [
	       'enctype' => 'multipart/form-data',
	      ]
	    ]); ?>
	
	    <?= $form->field($model, 'title')->textInput(['maxlength' => 255]) ?>
	    
	    <?= $form->field($model, 'type')->textInput(['maxlength' => 255]) ?>
	    
	    <?= $form->field($model, 'nav_id')->dropDownList(ArticleNav::getAllNav()) ?>
	
	    <?= $form->field($model, 'abstract')->textarea(['rows' => 3]) ?>
	
	    <?= $form->field($model, 'author')->textInput(['maxlength' => 25]) ?>
	
	    <h1>封面图</h1>
	    
	    <?= $this->render('//common/_image', ['model' => $model],['style'=>'width:200px;']);?>
	    
	    <h1>文章内容</h1>
	    <?php
	  echo \xj\ueditor\Ueditor::widget([
	      'model' => $model,
	      'attribute' => 'content',
	      'style' => 'width:100%;height:400px',
	      'renderTag' => true,
	      'readyEvent' => 'console.log("example2 ready")',
	      'jsOptions' => [
	          'serverUrl' => yii\helpers\Url::to(['/common/upload']),
	          'autoHeightEnable' => true,
	          'autoFloatEnable' => true
	      ],
	  ]);
	 ?>
	    <?= $form->field($model, 'click_num')->textInput() ?>
	
	    <?= $form->field($model, 'status')->dropDownList(['1'=>'生效','0'=>'失效']) ?>
	 <!-- 站点 -->
	     <span>站点</span>
	 <?php foreach($sites as $k=>$v) { ?>
            <input type="checkbox" name="site_id[]" value="<?=$k;?>" <?=in_array($k,$had_sites)?'checked':'';?>><?=$v;?>
     <?php }?>
		 <br/>
		 <br/>
		 <br/>
		 <input type="button" value="全选" class="btn btn-success" style="padding:1px;"  id="choseAll"/>&nbsp;&nbsp;&nbsp;
		 <input type="button" value="全不选" class="btn btn-success" style="padding:1px;"  id="delAll"/>&nbsp;&nbsp;&nbsp;
		 <input type="button" value="反选" class="btn btn-success" style="padding:1px;"  id="fanAll"/>
		 <br/>
		 <br/>
	    <div class="form-group">
        	<?= Html::submitButton('更新', ['class' => 'btn btn-primary']) ?>
    	</div>
	    
	    <?php ActiveForm::end(); ?>
	</div>
	<script>
	    //citys[0][]
	    //全部选择
	    $("#choseAll").click(function(){
	        $("input[name='site_id[]']").each(function(){
	            this.checked = true;
	        });
	    });
	    //取消选择
	    $("#delAll").click(function(){
	        $("input[name='site_id[]']").each(function(){
	            this.checked = false;
	        });
	    });
	    $("#fanAll").click(function(){
	        $("input[name='site_id[]']").each(function(){
	            if(this.checked == false){
	                this.checked = true;
	            }else{
	                this.checked = false;
	            }
	        });
	    });
	</script>
	